<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        * {
            margin: 0;
            padding: 0;
        }
        
        body {
            height: 2000px;
        }
        
        .top {
            width: 100%;
            height: 100px;
            background: yellowgreen;
        }
        
        .nav {
            width: 100%;
            height: 80px;
            background: pink;
        }
        
        .on {
            position: fixed;
            top: 0;
            left: 0;
        }
    </style>
</head>

<body>

    <div class="top">头部区域</div>
    <div class="nav">导航区域</div>


    <script src="../jQuery库/jquery-3.1.0.js"></script>
    <script>
        $(document).scroll(function() {
            let sTop = $(this).scrollTop();
            let dHeight = $(".top").height();
            if (sTop > dHeight) {
                $(".nav").addClass("on")
            } else {
                $(".nav").removeClass("on")
            }
        })
    </script>
</body>

</html>